package com.fwj.core.common.common;

/**
 * @Author: fwj
 * @Data: 2022/4/23 18:08
 * @Version 1.0
 * @Description:       重要信息处理工具
 */


public class ImportantInfoUtil {

    private static final String protectStr = "****";

    /**
     * 处理手机号
     * */
    public static String phone(Long phone){
        String ret =  new StringBuilder(String.valueOf(phone)).replace(3,8,protectStr).toString();
        return ret;
    }

    /**
     * 处理邮箱
     * */
    public static String email(String email){
        String pre = email.substring(0,4);
        String emailType = email.split("@")[1];
        return pre + protectStr + "@" + emailType;
    }

    /**
     * 处理身份证
     * */
    public static String idCard(String idCard){
        String ret =  new StringBuilder(idCard).replace(5,15,protectStr).toString();
        return ret;
    }


    /**
     * 处理微信
     * */
    public static String wechat(String wechat){
        String preStr = wechat.substring(0,3);
        int length = wechat.length();
        String postStr = wechat.substring(length - 3);
        return preStr + protectStr + postStr;
    }

    /**
     * 处理微信
     * */
    public static String qq(Long qq){
        String qqStr = String.valueOf(qq);
        int length = qqStr.length();
        String preStr = qqStr.substring(0,3);
        String postStr = qqStr.substring(length - 2);
        return preStr + protectStr + postStr;
    }

    /**
     * 处理其他类型的字符串
     * */
    public static String other(String other){
        int length = other.length();
        String preStr = other.substring(0,3);
        String postStr = other.substring(length - 3);
        return preStr + protectStr + postStr;
    }
}
